package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//TODO:全局异常处理
@ControllerAdvice //这个注解需要springmvc
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class) //填写异常类型
    @ResponseBody //返回json格式数据的异常信息
    public Result AllExceptionHandler (Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(HasRoomException.class)
    @ResponseBody
    public Result HasRoomException(HasRoomException e){
        return Result.fail(e.getMessage(), e.getCode());
    }
}
